package com.chunfen.wx.wa.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chunfen.wx.wa.domain.BtTemplate;
import com.chunfen.wx.wa.domain.User;
import com.chunfen.wx.wa.mapper.BtTemplateMapper;
import com.chunfen.wx.wa.mapper.UserMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
public class ViewController {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private BtTemplateMapper btTemplateMapper;

    @GetMapping("/viewindex")
    public String view(HttpServletRequest request, HttpServletResponse response){

        IPage<User> page = new Page<>();
        page.setCurrent(1);
        page.setSize(2);

        IPage<User> userIPage = userMapper.selectPage(page, null);

        BtTemplate btTemplate = new BtTemplate();

        btTemplate.setId(1L);

        IPage<BtTemplate> page2 = new Page<>();
        page2.setSize(2);
        page2.setCurrent(2);

        QueryWrapper<BtTemplate> queryWrapper = Wrappers.query();
        queryWrapper.eq("id", 1);

        btTemplateMapper.selectPage(page2, btTemplate);

        btTemplateMapper.selectList(btTemplate);


        System.out.println("this is test " + userIPage.getPages() + "|" + userIPage.getRecords());
        return "redirect:https://www.baidu.com";
    }
}
